package mhwi.cards.hunter;

import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.LoseStrengthPower;
import com.megacrit.cardcrawl.powers.StrengthPower;
import mhwi.cards.ShouDaoCard;
import mhwi.helper.ModHelper;

import static mhwi.constants.ResourcesConstant.EXTENSION_PNG;
import static mhwi.constants.ResourcesConstant.PATH_IMG_CARDS_HUNTER;

public class XianJingCard extends ShouDaoCard {
    private static final String CLASS_NAME = XianJingCard.class.getSimpleName();
    public static final String ID = ModHelper.makeId(CLASS_NAME);
    private static final CardStrings CARD_STRINGS = CardCrawlGame.languagePack.getCardStrings(ID);
    private static final String NAME = CARD_STRINGS.NAME;
    private static final String IMG_PATH = ModHelper.makeFileName(PATH_IMG_CARDS_HUNTER, CLASS_NAME, EXTENSION_PNG);
    private static final String DESCRIPTION = CARD_STRINGS.DESCRIPTION;

    private static final int COST = 2;
    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.ENEMY;

    public XianJingCard() {
        super(ID, NAME, IMG_PATH, COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.tags.add(CardTags.EMPTY);
        this.baseMagicNumber = 2;
        this.exhaust = true;
    }

    // 升级卡牌
    @Override
    public void upgrade() {
        if (!upgraded) {
            upgradeName();
            this.rawDescription = CARD_STRINGS.UPGRADE_DESCRIPTION;
            initializeDescription();
        }
    }

    // 使用卡牌
    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        // 给敌人施加失去力量的效果
        AbstractDungeon.actionManager.addToTop(new ApplyPowerAction(m, p, new StrengthPower(m, -this.baseMagicNumber), -this.baseMagicNumber));
        // 同时给敌人施加力量减少的效果，确保回合结束时力量减少
        if (!this.upgraded) {
            AbstractDungeon.actionManager.addToBottom(new ApplyPowerAction(m, p, new LoseStrengthPower(m, -this.baseMagicNumber), -this.baseMagicNumber));
        }
    }
}